package com.bop.dehong.loan.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.base.dehong.base.AdapterBase;
import com.base.dehong.util.StringUtils;
import com.bop.dehong.R;
import com.bop.dehong.info.TenderingInfo;

/**
 * 借款中适配器
 * @author Tangwenhan
 *2015-11-18下午5:40:07
 */
public class TenderingAdapter extends AdapterBase<TenderingInfo>{
	/**
	 * 我的借款 ： 0 招标中   1 还款中   2已还清
	 * 我的投资      3投标中    4收款中   5已还清
	 */
	private int mType = 0;

	public TenderingAdapter(Activity context, int type) {
		super(context);
		mType = type;
	}

	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_tendering_list, null);
			holder.titleTv = getView(convertView, R.id.textView1);
			holder.loanAmountTv = getView(convertView, R.id.textView4);
			holder.interestTv = getView(convertView, R.id.each);
			holder.paidPrincipalTv = getView(convertView, R.id.paid_principal);
			holder.remainsPrincipalTv = getView(convertView, R.id.remains_principal);
			holder.nperTv = getView(convertView, R.id.nper);
			holder.expirationTimeTv = getView(convertView, R.id.time);
			holder.iconIv = getView(convertView, R.id.icon);
			if (mType == 0) {
				((TextView)getView(convertView, R.id.textView5)).setText("应还利息：￥");
			}else if (mType == 1) {
				((TextView)getView(convertView, R.id.textView5)).setText("每期还款日：");
			}else if (mType == 2) {
				((TextView)getView(convertView, R.id.textView5)).setText("每期还款日：");
				((TextView)getView(convertView, R.id.textView7)).setText("已还利息");
			}else if (mType == 3) {
				((TextView)getView(convertView, R.id.textView3)).setText("投标金额：");
				((TextView)getView(convertView, R.id.textView5)).setText("预期收益：￥");
				((TextView)getView(convertView, R.id.textView8)).setText("已收本息");
				((TextView)getView(convertView, R.id.textView7)).setText("待收本息");
			}else if (mType == 4) {
				((TextView)getView(convertView, R.id.textView3)).setText("投标金额：");
				((TextView)getView(convertView, R.id.textView5)).setText("每期收益日：");
				((TextView)getView(convertView, R.id.textView8)).setText("已收本息");
				((TextView)getView(convertView, R.id.textView7)).setText("待收本息");
			}else if (mType == 5) {
				((TextView)getView(convertView, R.id.textView3)).setText("投标金额：");
				((TextView)getView(convertView, R.id.textView5)).setText("每期收益日：");
				((TextView)getView(convertView, R.id.textView8)).setText("已收本金");
				((TextView)getView(convertView, R.id.textView7)).setText("实收利息");
			}
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		TenderingInfo info = get(arg0);
		if (mType != 0) {
			holder.expirationTimeTv.setText(info.limittime);
		}
		if (mType == 0 || mType == 3) {
			holder.interestTv.setText(info.interest);
		}else{
			holder.interestTv.setText(info.next_day+"号");
		}
		setIcon(holder.iconIv,info.product);
		holder.titleTv.setText(info.title);
		holder.loanAmountTv.setText("￥"+StringUtils.getThousandFormatValue(info.money));
		holder.paidPrincipalTv.setText("￥"+StringUtils.getThousandFormatValue(info.hadpaid));
		holder.remainsPrincipalTv.setText("￥"+StringUtils.getThousandFormatValue(info.notpaid));
		holder.nperTv.setText(info.nper);
		return convertView;
	}
	
	private class ViewHolder {
		//标题
		private TextView titleTv;
		// 到期时间
		private TextView expirationTimeTv;
		//借款金额
		private TextView loanAmountTv;
		//利息
		private TextView interestTv;
		//已还
		private TextView paidPrincipalTv;
		//待还本金
		private TextView remainsPrincipalTv;
		//待还本金
		private TextView nperTv;
		
		private ImageView iconIv; 
				
	}
	/**
	 * 
	 * @param view
	 * @param type 1德盈票乐宝 2德盈房易通 3德盈车易通 4 体验宝 5 德盈信易通
	 */
	private void setIcon(ImageView view,String type){
		if ("1".equals(type)) {
			view.setImageResource(R.mipmap.piaolebao);
		}else if ("2".equals(type)) {
			view.setImageResource(R.mipmap.fangyitong);
		}else if ("3".equals(type)) {
			view.setImageResource(R.mipmap.cheyitong);
		}else if ("4".equals(type)) {
			view.setImageResource(R.mipmap.tiyanbao);
		}else if ("5".equals(type)) {
			view.setImageResource(R.mipmap.xinyitong);
		}else {
			view.setImageResource(0);
		}
	}

}

